﻿Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Public Class Invoice
    Dim cmd As New SqlCommand
    Private Sub Invoice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        condb()
        'For select invoice id
        cmd.Connection = cn
        cmd.CommandText = "select top(1)InvoiceID  from tblorder order by InvoiceID desc "
        Dim invoice = cmd.ExecuteScalar
        '   ......................
        cmd.Connection = cn
        cmd.CommandText = "select o.*,d.* from tblorder o inner join tblorderDetial d ON o.InvoiceID =d.InvoiceID where o.InvoiceID =@ID"
        cmd.Parameters.Add("@ID", SqlDbType.Int).Value = invoice
        Dim dr = cmd.ExecuteReader
        Dim dt As New DataTable
        dt.Load(dr)
        dr.Close()
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", dt))
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "stock.invoiceReport1.rdlc"
        Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
        Me.ReportViewer1.ZoomMode = ZoomMode.FullPage
        Me.ReportViewer1.RefreshReport()
        Me.ReportViewer1.RefreshReport()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Close()
    End Sub

End Class